package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import metier.Specialite;
import metier.Spectacle;

public class DaoSpecialite 
{

	public static int AjoutSpecialite (Specialite uneSpe) throws ClassNotFoundException, SQLException
	{
		String chaine = "jdbc:mysql://localhost/";
		String req;
		Connection connec;
		connec = MySqlConnection.getConnection(chaine + "mlr1", "root", "");
		req = "insert into specialite values (" + uneSpe.getCodeSpe() + ", '" + uneSpe.getLibSpe() + "')";
		System.out.println(req);
		return 1;
	}
	
	public static Vector <Specialite> getLesSpe () throws ClassNotFoundException, SQLException
	{
		String chaine = "jdbc:mysql://localhost/";
		Statement stLienBd = null;
		ResultSet res = null;
		String req;
		Connection connec;
		Vector <Specialite> lesSpecialites;
		Specialite laSpe;
		connec = MySqlConnection.getConnection(chaine + "mlr1", "root", "");
		stLienBd = connec.createStatement();
		lesSpecialites = new Vector <Specialite>();
		try
		{
			
			req = "select * from specialite";
			res = stLienBd.executeQuery(req);
			while (res.next())
			{
				laSpe = new Specialite (res.getInt(1), res.getString(2));
				lesSpecialites.add(laSpe);
			}
			res.close();
			connec.close();
		}
		catch (Exception e)
		{
			System.out.println(e.getMessage());
		}
		return lesSpecialites;
	}
}
